package com.design.patterns.list.state.eg;

/**
 * 抽奖状态上下文
 *
 * @author Wangzhiwen
 */
public class ActivityContext {

    /**
     * 状态委派对象
     */
    private ActivityState state;

    /**
     * 奖品数量
     */
    private int count;

    /**
     * 聚合所有状态
     */
    public final NoState noState;
    public final CanState canState;
    public final DispenseState dispenseState;
    public final DispenseOutState dispenseOutState;

    public ActivityContext(int count) {
        noState = new NoState(this);
        canState = new CanState(this);
        dispenseState = new DispenseState(this);
        dispenseOutState = new DispenseOutState();
        if (count > 0) {
            this.state = noState;
        }
        this.count = count;
    }

    public void deduct() {
        state.deduct();
    }

    public void lottery() {
        if (state.lottery()) {
            state.grant();
        }
    }

    public ActivityState getState() {
        return state;
    }

    public void setState(ActivityState state) {
        this.state = state;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

}
